package com.lcke.demo.controller;

import com.lcke.common.rest.PageInfo;
import com.lcke.common.rest.Result;
import com.lcke.demo.entity.News;
import com.lcke.demo.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * (News)表控制层
 *
 * @author makejava
 * @since 2020-11-09 12:11:46
 */
@RestController
@RequestMapping("/news")
public class NewsController {
    /**
     * 服务对象
     */
    @Autowired
    private NewsService newsService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public News selectOne(Integer id) {
        return this.newsService.queryById(id);
    }

    @GetMapping("insert")
    public News insert(@RequestBody(required = false) News param) {
        return this.newsService.insert(param);
    }

    @GetMapping("delete")
    public Result deleteById(Integer id) {
        boolean byId = this.newsService.deleteById(id);
        return Result.okData(byId);
    }

    @GetMapping("update")
    public Result update(@RequestBody(required = false) News param) {
        News update = this.newsService.update(param);
        return Result.okData(update);
    }

    /**
     * 分压查询
     *
     * @param news
     * @return
     */
    @GetMapping("page")
    public PageInfo selectOne(News news) {
        return this.newsService.page(news);
    }

}